class Wall < ActiveRecord::Base
  belongs_to :profile
  
  validates_presence_of :author
  validates_presence_of :profile_id
  validates_presence_of :text
  
  validates_numericality_of :author
  validates_numericality_of :profile_id
  
  def validate
    # check if user and profile exists
    profile = Profile.find_by_id(self.profile_id)
    user    = User.find_by_id(self.author)
    
    if !profile
      errors.add_to_base("No profile with this id found")
    end
    if !user
      errors.add_to_base("No user with this id found")
    end
  end
end
